package be.fedict.eid.diagnostics.tests;

import be.fedict.eid.diagnostics.DiagnosticTest;
import be.fedict.eid.diagnostics.TestFailedException;
import be.fedict.eid.diagnostics.annotations.TestName;
import be.fedict.eid.diagnostics.helper.DataTreeBuilder;
import be.fedict.eid.diagnostics.system.OSException;
import be.fedict.eid.diagnostics.system.OperatingSystem;
import be.fedict.eid.diagnostics.system.data.SystemService;

@TestName("Data Acquisition: Certificate Propagation Service")
public class CertificatePropagationStatus extends DiagnosticTest {

	protected boolean runTest() throws TestFailedException {
		
		OperatingSystem os;
		try {
			os = new OperatingSystem();
		} catch (OSException e) {
			throw new TestFailedException("Could not establish type of Operating System.");
		}
		
		SystemService smartCardService = os.getServiceManager().getService("CertPropSvc");
		
		if (smartCardService == null) {
			throw new TestFailedException("Could not find the Certificate Propagation Service (CertPropSvc).");
			
		} else {
			rootNode.add(DataTreeBuilder.buildNode("state", smartCardService.getStatus().toString()));
		}
		
		return true;
		
	}

	protected String getRootName() {
		return "certpropsvc";
	}

}
